import React from "react"

export default class Course extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      count: 0,
    }
  }

  componentDidMount() {
    console.log(this.state.count)
    fetch(`${this.props.courseUrl}/${this.props.studentId}`)
      .then((res) => res.text())
      .then((json) => {
        console.log(JSON.parse(json))
        this.setState({ course: JSON.parse(json) })
      })
  }

  render() {
    return (
      <div>
        <h1>Course.jsx</h1>
        {this.state.course !== undefined &&
          this.state.course.map((item, i) => (
            <div key={i}>
              <p>课程名称：{item.cName}</p>
              <p>授课教师：{item.teacher.tName}</p>
              <button>上课</button>
              <hr />
            </div>
          ))}
      </div>
    )
  }
}
